


#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include "I_O_Disco.h"


void leerSector(FILE *filename, int32_t sector,void *buffer)
{
	int32_t posicion = sector * 512;
	fseek(filename, posicion,SEEK_SET);
	fread_unlocked(buffer, 512, 1 , filename);
	return  ;
}


void escribirSector(FILE *filename, int32_t sector,void *buffer)
{
	int32_t posicion = sector * 512;
	fseek(filename, posicion,SEEK_SET);
	int32_t sb = fwrite_unlocked(buffer,512,1,filename);
	if (sb != 1)
		printf("Error en escritura\n");
	return ;
}

//void leerSectorMAP(void *punteroMap, int32_t sector,char *buffer[512]){
void leerSectorMAP(void *punteroMap, int32_t sector,char *buffer){
	u_int32_t *posicion = punteroMap + (sector * 512);
	memcpy(buffer,posicion, 512);
	return ;


}

void escribirSectorMAP(void *punteroMap, int32_t sector,char *buffer[512]){
	u_int32_t *posicion = punteroMap + (sector * 512);
	memcpy(posicion, buffer, 512);
//	if (msync(punteroMap, 512, MS_SYNC) != 0)
//		perror("msync");
	return ;
}

void escribirSectorMAP2(void *punteroMap, int32_t sector,unsigned char *buffer){
	memcpy(punteroMap + (sector * 512), buffer, 512);
	if (msync(punteroMap, 512, MS_SYNC) != 0)
		perror("msync");
	return ;
}

